//
//  UserViewController.m
//  EasyChat
//
//  Created by dllo on 16/6/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "UserViewController.h"
#import "UserTableViewCell.h"
#import "UserHeaderTableViewCell.h"
#import "UserHeaderDetailViewController.h"
#import "SettingViewController.h"
static NSString *const CELL = @"cell";
static NSString *const HeaderCELL = @"HeaderCell";
@interface UserViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,retain)UITableView *myTableView;
@end

@implementation UserViewController
-(void)dealloc{
    [_myTableView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"我的";
    //修改导航栏标题的颜色 和 大小
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],
                                                                      
                                                                      NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self createTableView];
}
-(void)createTableView{
    self.myTableView = [[UITableView alloc] initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    
//    self.myTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    UIView *footerView = [[UIView alloc] init];
    footerView.backgroundColor = [UIColor colorWithRed:0.88 green:0.88 blue:0.88 alpha:1.0];
    self.myTableView.tableFooterView = footerView;
    
    [self.view addSubview:self.myTableView];
    [self.myTableView registerClass:[UserTableViewCell class] forCellReuseIdentifier:CELL];
    [self.myTableView registerClass:[UserHeaderTableViewCell class] forCellReuseIdentifier:HeaderCELL];
//    self.myTableView.separatorStyle = 0;
    [_myTableView release];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }
    else if (section == 1){
        return 4;
    }
    else if (section == 2){
        return 1;
    }
    else{
        return 1;
    }

}

//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
//    if (section == 0) {
//        return 95;
//    }
//    else return 30;
//}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 10;
    }
    else{
        return 20;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 95;
    } else {
        return 50;
    }
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {
        UserHeaderTableViewCell *HeaderCell = [tableView dequeueReusableCellWithIdentifier:HeaderCELL forIndexPath:indexPath];
        HeaderCell.headImage.image = [UIImage imageNamed:@""];
        HeaderCell.accountLabel.text = @"ID:";
        HeaderCell.nikeLabel.text = @"🌻";
        HeaderCell.IDLabel.text = @"8888👑";
        HeaderCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//        HeaderCell.selectionStyle = 0;
        return HeaderCell;
    }
    else{
         UserTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CELL forIndexPath:indexPath];
        if (indexPath.section == 1 && indexPath.row == 0)
        {
            cell.myImage.image = [UIImage imageNamed:@"相册"];
            cell.myLabel.text = @"相册";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        else if (indexPath.section == 1 && indexPath.row == 1)
        {
            cell.myImage.image = [UIImage imageNamed:@"收藏"];
            cell.myLabel.text = @"收藏";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        else if (indexPath.section == 1 && indexPath.row == 2)
        {
            cell.myImage.image = [UIImage imageNamed:@"钱包"];
            cell.myLabel.text = @"钱包";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        else if (indexPath.section == 1 && indexPath.row == 3)
        {
            cell.myImage.image = [UIImage imageNamed:@"卡卷"];
            cell.myLabel.text = @"卡卷";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        else if (indexPath.section == 2 && indexPath.row == 0)
        {
            cell.myImage.image = [UIImage imageNamed:@"表情"];
            cell.myLabel.text = @"表情";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        else if (indexPath.section == 3 && indexPath.row == 0)
        {
            cell.myImage.image = [UIImage imageNamed:@"设置"];
            cell.myLabel.text = @"设置";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
//        cell.selectionStyle = 0;
        return cell;
    }

}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0 && indexPath.row == 0){
        UserHeaderDetailViewController *detail = [UserHeaderDetailViewController new];
        [self.navigationController pushViewController:detail animated:YES];
    }
    if (indexPath.section == 3 && indexPath.row == 0) {
        SettingViewController *settingVC = [SettingViewController new];
        [self.navigationController pushViewController:settingVC animated:YES];
    }
    
    
}










- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
